package cn.edu.lingnan.controller;

import cn.edu.lingnan.utils.AliOSSUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping()
@RequiredArgsConstructor
@Slf4j
public class UploadController {

    private final AliOSSUtils aliOSSUtils;


    @PostMapping("/uploadProjectImg")
    public Result  uploadProjectImg(MultipartFile image,Integer projectId) throws IOException {
        String url=  aliOSSUtils.uploadReplace( image,projectId);//调用工具类上传文件
        log.info("文件上传完成：{}" ,url);
        return Result.success(url);//返回路径
    }

    //上传项目文件,不要projectId参数
    @PostMapping("/uploadAddProjectImg")
    public Result   uploadAddProjectImg(MultipartFile file) throws IOException {
        String url=  aliOSSUtils.upload( file);//调用工具类上传文件
        log.info("文件项目上传完成：{}" ,url);
        return Result.success(url);//返回路径
    }
    //删除项目图片
    @DeleteMapping("/deleteProjectImg")
    public Result deleteProjectImg( @RequestParam("url") String url){
        aliOSSUtils.delete(url);
        return Result.success();
    }
}
